ABC245 C - Choose Elements
https://atcoder.jp/contests/abc245/tasks/abc245_c
提出
code: python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# 全探索は計算量オーバー
for i in range(n-1):
if (abs(ai - ai+1) > k and abs(ai - bi+1) > k and abs(bi - bi+1) > k and abs(bi - ai+1) > k):
print('No')
exit()
print('Yes')
解答
code: python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ap = False for _ in range(n) # (X1, X2...Xi)まで考慮したとき、Xi = Aiとしてよいか
bp = False for _ in range(n) # (X1, X2...Xi)まで考慮したとき、Xi = Biとしてよいか
ap0 = True
bp0 = True
for i in range(1, n):
if (api-1):
if(abs(ai-1 - ai) <= k):
api = True
if(abs(ai-1 - bi) <= k):
bpi = True
if(bpi-1):
if(abs(bi-1 - ai) <= k):
api = True
if(abs(bi-1 - bi) <= k):
bpi = True
if(apn-1 or bpn-1):
print("Yes")
else:
print("No")
テーマ
#dp
メモ
https://atcoder.jp/contests/abc245/editorial/3634
提出
code: python
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# X = (a,b) どちらかを選択
# (1,3), (5,6), (4,6), (5,2)
# (5,7), (4,3), (7,5), (4,7)
# (o,o), (x,x), (o,x), (x,o)
# (x,x), (o,o), (x,x), (o,x)
ta = []
tb = []
for i in range(n-1):
ta.append((True if abs(ai-ai+1) <= k else False, True if abs(ai-bi+1) <= k else False))
tb.append((True if abs(bi-bi+1) <= k else False, True if abs(bi-ai+1) <= k else False))
for i in range(n-2):
if tai0 and (tai+10 or tai+11):
continue
if tai1 and (tbi+10 or tbi+11):
continue
if tbi0 and (tbi+10 or tbi+11):
continue
if tbi1 and (tai+10 or tai+11):
continue
print("No")
exit()
print("Yes")